package com.smbms.entity;

import org.aspectj.lang.JoinPoint;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Component;

@Configuration
@EnableAspectJAutoProxy
@Component
@Aspect
public class UserServiceAdvice {
	
//	定义局部切点
	@Pointcut("execution(* com.smbms.pojo.*.*(..) )")
	public void pc(){
		
	}
	
//	切面前置增强
	@Before("pc()")
	public void myBefore1(JoinPoint jp){
		System.out.println("前置增强：模拟权限检查");//输出增强内容
		System.out.println("被增强的目标类是："+jp.getTarget());//输出增强内容
	}
	
//	后置增强
	@AfterReturning("pc()")
	public void myAfterReturning1(JoinPoint jp){
		System.out.println("后置增强：模拟记录日志");//输出增强内容
		System.out.println("被织入的目标方法是："+jp.getSignature().getName());//输出增强内容
	}
	
//	异常抛出增强
	@AfterThrowing(pointcut="pc()",throwing="e")
	public void myAfterThrowing(JoinPoint jp, RuntimeException e){
		System.out.println("3.异常抛出增强");
		e.printStackTrace();
	}
	
//	最终增强
	@After("pc()")
	public void myFinally(JoinPoint jp){
		System.out.println("4.最终增强");
		System.out.println("释放资源");
		
	}
	
//	环绕增强
	@Around("pc()")
	public void myAround(ProceedingJoinPoint jp) throws Throwable{
		System.out.println("5.环绕增强---开始");
		jp.proceed();
		System.out.println("5.环绕增强---结束");
	}
	
}
